<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<link rel="stylesheet" href="${pageContext.request.contextPath}/static/plugin/layui/css/layui.css" media="all">

<table class="layui-table">
    <colgroup>
        <col width="150">
        <col width="200">
        <col>
    </colgroup>
    <thead>
    <tr>
        <th>序号</th>
        <th>title</th>
        <th>状态</th>
        <th>发布时间</th>
        <th>分类</th>
        <th>标签</th>
        <th>创建时间</th>
        <th>修改时间</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody>
    <c:forEach items="${pageInfo.list}" var="item" varStatus="i">
        <tr>
            <td>${i.index+1}</td>
            <td>${item.blogName}</td>
            <td>${item.blogType eq 1?'已发布':'草稿'}</td>
            <td>${item.releasetime}</td>
            <td>${item.typestr}</td>
            <td>${item.label}</td>
            <td>${item.createtime}</td>
            <td>${item.updatetime}</td>
            <td>
                <button class="layui-btn layui-btn-xs" onclick="updateStatus('${item.id}','${item.blogType}')">发布</button>
                <a href="${pageContext.request.contextPath}/bloginfo/go_bloginfo_saveorupdate.html?id=${item.id}"
                   class="layui-btn layui-btn-xs">修改</a>
                <button class="layui-btn layui-btn-xs" onclick="delBlogInfo('${item.id}')">删除</button>
            </td>
        </tr>
    </c:forEach>
    </tbody>
</table>

<div id="page_div"></div>
<script src="${pageContext.request.contextPath}/static/js/jquery-2.1.1.min.js"></script>
<script src="${pageContext.request.contextPath}/static/plugin/layui/layui.all.js"></script>
<script>
    var laypage = layui.laypage;
    var layer = layui.layer;
    //完整功能
    laypage.render({
        elem: 'page_div'
        , count: '${pageInfo.total}'
        , limit: '${pageInfo.pageSize}'
        , limits: [10, 15, 30]
        , curr: '${pageInfo.pageNum}'
        , layout: ['count', 'prev', 'page', 'next', 'limit', 'refresh', 'skip']
        , jump: function (obj, first) {
            if (!first) {
                load_page(obj.curr, obj.limit);
            }
        }
    });

    function updateStatus(id,type) {
        if(type==1){
            layer.msg("已经发布");
        }else {
            $.ajax({
                url: '${pageContext.request.contextPath}/bloginfo/updateStatus',
                type: 'post',
                dataType: 'json',
                data: {'id': id},
                async: false,
                success: function (result) {
                    if (result.status) {
                        load_page('${pageInfo.pageNum}', '${pageInfo.pageSize}');
                    } else {
                        layer.msg(result.msg);
                    }
                },
                error: function () {
                    alert("异常！");
                }
            });
        }
    }

    function delBlogInfo(id) {
        layer.confirm('确认删除这个博客吗?', function (index) {
            $.ajax({
                url: '${pageContext.request.contextPath}/bloginfo/delBlogInfo',
                type: 'post',
                dataType: 'json',
                data: {'id': id},
                async: false,
                success: function (result) {
                    layer.msg(result.msg);
                    if (result.status) {
                        load_page('${pageInfo.pageNum}', '${pageInfo.pageSize}');
                    }
                },
                error: function () {
                    alert("异常！");
                }
            });
        });

    }

</script>

